package com.ruoyi.merchant.controller;

import com.ruoyi.common.core.cg.pojo.Group;
import com.ruoyi.merchant.service.GroupService;
import com.ruoyi.merchant.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/group")
public class GroupController {
    @Autowired
    private GroupService groupService;

    //查询所有
    @RequestMapping("/list")
    public Result groups(){
        return groupService.groupList();
    }

    /**
     * 添加拼团信息
     * @param group
     * @return
     */
    @RequestMapping("/save")
    public Result saveGroup(
            @ModelAttribute Group group,
            @RequestParam(value = "surfacePlotFile", required = false) MultipartFile surfacePlotFile,
            @RequestParam(value = "firstImgFile", required = false) MultipartFile firstImgFile,
            @RequestParam(value = "secondImgFile", required = false) MultipartFile secondImgFile) {
        return groupService.saveGroup(group, surfacePlotFile, firstImgFile, secondImgFile);
    }

    @RequestMapping("/lid")
    public Result queryGroup(int lid){
        List<Group> groups = groupService.queryGroup(lid);
        return Result.ok(groups);
    }
}
